<?php
	include_once "../classes/binhluan_quanly_bs.php";
	include_once "../classes/thuvienham.php";
	if(!IsAdmin())
		header("Location: index.php");
	
	if(isset($_POST['BinhLuan']) && isset($_POST['Captcha']) &&
	   isset($_POST['KiemDuyet']) && isset($_POST['DoDai']) && 
	   isset($_POST['SoBL']))
	{
		$qlbl = new binhluan_quanly_bs();
		$qlbl->SetChoPhepBinhLuan((int)$_POST['BinhLuan']);
		$qlbl->SetCaptcha((int)$_POST['Captcha']);
		$qlbl->SetKiemDuyet((int)$_POST['KiemDuyet']);
		$qlbl->SetDoDaiToiDa((int)$_POST['DoDai']);
		$qlbl->SetSoBinhLuanMoiTrang((int)$_POST['SoBL']);
		
		$qlbl->CapNhat();
	}
	$qlbl = new binhluan_quanly_bs();
	$data_qlbl = $qlbl->LayDanhSach();
?>

<div class="QuanLyMenu">
	<div class="Phai">
		<h4 align="center">Cài đặt các tùy chọn cho bình luận bài viết</h4>
		<form action="index.php?actionad=binhluan_caidat" method="POST">
			<div class="TuyChonPhanTrang">
				<table class="CDPhanTrang">
					<tr>
						<?php
							$tmp = $data_qlbl[0]['ChoPhepBinhLuan'];
						?>
						<td>Cho phép người đọc bình luận</td>
						<td>
							<input id="NDBL0" name="BinhLuan" type="radio" value="0" <?php echo ($tmp == 0) ? 'checked="true"' : ''; ?>/>
							<label for="NDBL0">Không</label>
							&nbsp;&nbsp; 
							<input id="NDBL1" name="BinhLuan" <?php echo ($tmp == 1) ? 'checked="true"' : ''; ?> type="radio" value="1" /> 
							<label for="NDBL1">Có</label>
						</td>
					</tr>
					<tr>
						<?php
							$tmp = $data_qlbl[0]['Captcha'];
						?>
						<td>Nhập mã xác nhận - Captcha</td>
						<td>
							<input id="CAP0" name="Captcha" type="radio" value="0" <?php echo ($tmp == 0) ? 'checked="true"' : ''; ?>/>
							<label for="CAP0">Không</label>
							&nbsp;&nbsp;
							<input id="CAP1" name="Captcha" <?php echo ($tmp == 1) ? 'checked="true"' : ''; ?> type="radio" value="1" />
							<label for="CAP1">Có</label>
						</td>
					</tr>
					<tr>
						<?php
							$tmp = $data_qlbl[0]['KiemDuyet'];
						?>
						<td>Kiểm duyệt bình luận</i></td>
						<td>
							<input id="KD0" name="KiemDuyet" type="radio" value="0" <?php echo ($tmp == 0) ? 'checked="true"' : ''; ?>/>
							<label for="KD0">Không</label>
							&nbsp;&nbsp;
							<input id="KD1" name="KiemDuyet" type="radio" value="1" <?php echo ($tmp == 1) ? 'checked="true"' : ''; ?> />
							<label for="KD1">Có</label>
						</td>
					</tr>
					<tr hidden="true">
						<?php
							$tmp = $data_qlbl[0]['DoDaiToiDa'];
						?>
						<td>Độ dài tối đa cho mỗi lượt bình luận</td>
						<td><input type="number" name="DoDai" id="SoBaiViet" value="<?php echo $tmp; ?>"/></td>
					</tr>
					<tr hidden="true">
						<?php
							$tmp = $data_qlbl[0]['SoBinhLuanMoiTrang'];
						?>
						<td>Số bình luận hiển thị gần nhất trên mỗi trang</i></td>
						<td><input type="number" name="SoBL" id="SoTrangLienKe" value="<?php echo $tmp; ?>"/></td>
					</tr>
				</table>
				<table class="CDPhanTrangS">
					<tr>
						<td align="center"><input class="btn_submit" type="submit" value="Cập nhật"/></td>
					</tr>
				</table>
			</div>
		</form>
	</div>
</div>

<script>
	var tmp1 = $('#SoBaiViet').val();
	$('#SoBaiViet').change(function(){
		var t1 = $(this).val();
		if(t1 >= 5 && t1 <= 20)
			tmp1 = t1;
		else
			t1 = tmp1;
		$(this).val(t1);
	});
	
	var tmp = $('#SoTrangLienKe').val();
	$('#SoTrangLienKe').change(function(){
		var t = $(this).val();
		if(t >= 2 && t <= 10)
		{
			if(t % 2 != 0)
			{
				if(t > tmp)
				{
					t++;
					tmp = t;
				}
				if(t < tmp)
				{
					t--;
					tmp = t;
				}
			}
		}
		else
		{
			t = tmp;
		}
		$('#SoTrangLienKe').val(t);
	});
</script>